package com.example.fete.View;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Toast;

import com.example.fete.Base.BaseActivity;
import com.example.fete.Base.Customs;
import com.example.fete.Customs.IosAlertDialog;
import com.example.fete.R;
import com.example.fete.Utils.SPUtils;
import com.example.fete.Utils.ToastUtil;
import com.example.fete.Utils.UIHandler;

public class WelcomeActivity extends BaseActivity {

    private static WelcomeActivity welcomeActivity;
    private UIMyHandler handler;

    private static class UIMyHandler extends UIHandler<WelcomeActivity> {

        public UIMyHandler(WelcomeActivity cls) {
            super(cls);
        }
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            WelcomeActivity activity = reference.get();
            if (activity != null) {
                if (activity.isFinishing()) {
                    return;
                }
                switch (msg.what) {
                    case Customs.HANDLER_SPLASH:
                        if (isFirst()) {
                            activity.startActivity(new Intent(activity, GuideActivity.class));
                        } else {
                            activity.startActivity(new Intent(activity, HomeActivity.class));
                        }
                        break;

                }
            }

        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        welcomeActivity = this;
    }

    @Override
    protected void initHanler() {
        handler = new UIMyHandler(WelcomeActivity.this);
    }

    @Override
    protected void initView() {
        handler.sendEmptyMessageDelayed(Customs.HANDLER_SPLASH, 2000);
        new IosAlertDialog(WelcomeActivity.this).builder().setTitle("退出当前账号")
                .setMsg("再连续登陆15天，就可变身为QQ达人。退出QQ可能会使你现有记录归零，确定退出？")
                .setPositiveButton("确认退出", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                    }
                }).setNegativeButton("取消", new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        }).show();
    }

    @Override
    public int initXmlID() {
        return R.layout.activity_welcome;
    }

    private static boolean isFirst() {
        boolean isFirst = (boolean)SPUtils.get(welcomeActivity, Customs.SHARE_IS_FIRST, true);
        if (isFirst) {
            SPUtils.put(welcomeActivity,Customs.SHARE_IS_FIRST,false);
            return true;
        }else {
            return false;
        }
    }
}
